/******************************************************************************
 ********************************* Card.java **********************************
 * @author Scott DiTomaso *****************************************************
 * Kettering University *******************************************************
 ******************************************************************************
 * Created on December 11, 2009 ***********************************************
 ******************************************************************************/

package openbridge;

/***********
 * Imports *
 ***********/
import javax.swing.*;
import java.awt.*;

/**************
 * Card class *
 **************/
public class Card {

    /*************************
     * Private class members *
     *************************/
        private int suit;
        private int value;
        private String face;
        private String back;
	private JLabel image;
	private String pos;


        /****************
         * Constructors *
         ****************/
        Card(int s, int v, String f, String b) {
            this.suit = s;
            this.value = v;
            this.face = f;
            this.back = b;
	    this.pos = null;
        }
        Card() {
            this.suit = -1;
            this.value = -1;
            this.face = null;
            this.back = null;
	    this.pos = null;
        }


    /************************
     * Public class members *
     ************************/

	/**********************************************************************
	 * getSuit() **********************************************************
	 **********************************************************************
	 * Returns the suit of a given card as a String ***********************
	 **********************************************************************/
        public String getSuit() {

           switch(this.suit) {
               case 0:
                   return "Club";
               case 1:
                   return "Diamond";
               case 2:
                   return "Heart";
               case 3:
                   return "Spade";
               default:
                   return "ERROR";
           }
        }
	/**********************************************************************
	 * getNumSuit() *******************************************************
	 **********************************************************************
	 * Returns the suit of a given card as an Int between 0 and 4 *********
	 **********************************************************************/
        public int getNumSuit() {

	   return this.suit;
	}

	/**********************************************************************
	 * getValue() *********************************************************
	 **********************************************************************
	 * Returns the value of a given card as a Int between 2 and 14 ********
	 **********************************************************************/
        public int getValue() {

            switch (this.value) {
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                case 10:
                case 11:
                case 12:
                case 13:
                case 14:
                    return this.value;
                default:
                    return -1;
            }
        }

	/**********************************************************************
	 * getSortValue() *****************************************************
	 **********************************************************************
	 * Returns a value based on the cards face value and suit for sorting *
	 * purposes, since the suits are ranked it works nicely ***************
	 **********************************************************************/
	public int getSortValue() {

	    return( (13*this.suit) + (this.value) );
	}

	/**********************************************************************
	 * display() **********************************************************
	 **********************************************************************
	 * calls OpenBridgeGUI.display() with either the front or back of a ***
	 * given card in a specified position *********************************
	 **********************************************************************/
	public void display(boolean isVisible, OpenBridgeGUI g, String pos, int x) {

	    this.pos = pos;

	    if(isVisible)
		g.display(this.face, this.pos, x);
	    else
		g.display(this.back, this.pos, x);
	}

	/**********************************************************************
	 * flipCard() *********************************************************
	 **********************************************************************
	 * Flips a given face down card to face up in a specified position ****
	 **********************************************************************/
	public void flipCard(OpenBridgeGUI g, int x) {

	    g.flip(this.face, this.pos, x);
	}
}
